package com.guli.sta.task;

import com.guli.sta.service.DailyService;
import com.guli.sta.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author ZHAOZHENYU
 * @since 2022/10/5
 */

@Component
public class ScheduledTask {

    @Autowired
    private DailyService dailyService;

//    @Scheduled(cron = "0/5 * * * * ?")    // 测试5秒执行一次
    public void task1(){
        System.out.println("******************task1执行了**********");
    }

    /**
     * 每天1点执行
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void staTask(){

        // 前一天的日期
        String day = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        dailyService.createStatisticsByDay(day);

    }

}
